<template>
    <div>   
        <h3>修改</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">活动标题</td>
                    <td><input type="text" v-model="info.Huodongxx"></td>
                </tr>
                <tr>
                    <td align="right">图片</td>
                    <td><input type="file" @click="img">
                        <img :src="info.HudongPhoto" width="60" height="60" v-if="info.HudongPhoto!=''">
                        </td>
                </tr>
                <tr>
                    <td align="right">状态</td>
                    <td>
                         <input type="radio"    name="Stares" v-model="info.Stares" :value="true">进行中
                         <input type="radio"    name="Stares" v-model="info.Stares" :value="false">未进行
                    </td>    
                  
                </tr>

                <tr>
                    <td align="right">分类</td>
                    <td>
                        <select v-model="info.Fid">
                                 <option value="">请选择</option>
                                <option :value="item.Id" v-for="item in err">{{ item.LieName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">活动时间</td>
                    <td><input type="date" v-model="info.HuoTime"></td>
                </tr>
                <tr>
                    <td align="right">活动地点</td>
                    <td><input type="text" v-model="info.Huodng"></td>
                </tr>
                <tr>
                    <td align="right">更新人</td>
                    <td><input type="text" v-model="info.Gxname"></td>
                </tr>
                <tr>
                    <td align="right">跟新时间</td>
                    <td><input type="date" v-model="info.GxTime"></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="修改" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted}from 'vue'
import axios from 'axios';
import moment from 'moment';
import{useRoute,useRouter}from 'vue-router'
const route=useRoute();
const router=useRouter();

let info:any=reactive({
 "Id":route.query.id,
  "Huodongxx": "",
  "HudongPhoto": "",
  "Stares": "",
  "Fid": "",
  "HuoTime": "",
  "Huodng": "",
  "Gxname": "",
  "GxTime": "",
})

onMounted(()=>{
    bangding();
    fantian();
})
//绑定下拉框
let err:any=ref([])

const bangding=()=>{
    axios({
        url:'/api/User/Binghd',
        method:'get'
    })
    .then((res)=>{
        err.value=res.data
    })
}
//反填
const fantian=()=>{
    axios({
        url:'/api/User/Fantian',
        method:'get',
        params:{
            id:route.query.id
        }
    })
    .then((res)=>{
        Object.assign(info,res.data);
        info.HuoTime=res.data.HuoTime.substr(0,10)
        info.GxTime=res.data.GxTime.substr(0,10)

    })
}

const ok=()=>{
    if(info.Huodongxx==""){
        alert("活动标题不能为空");
        return;
    }
     if(info.HudongPhoto==""){
        alert("图片不能为空");
        return;
    }
    if(info.Fid==""){
        alert("分类不能为空");
        return;
    }
   
    axios({
        url:'/api/User/Updatexg',
        method:'put',
        data:info
    })
    .then((res)=>{
        if(res.data>0){
            alert("修改成功")
            router.push('/huoList')
            
            return
        }
        else
        {
            alert("修改失败")
            return;
        }
    })
}
//图片上传
const img=(e:any)=>{
    var obj=e.target.files[0]
    var f=new FormData()
    f.append('file',obj)
    axios({
        url:'/api/File/Img',
        method:'post',
        data:f
    })
    .then((res)=>{
        if(res.data!=0){
            
            alert("上传成功");
            return 
            
        }
        else
        {
            alert('上传失败')
            return 
        }
    })
}
</script>

<style scoped>

</style>